package com.ciwong.epaper.modules.epaper.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.evaluate.bean.DubVideoCatalogue;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:配音专辑适配器
 * @author: wyk
 * @time: 2022/1/18 16:01
 */
public class DubVideoAlbumAdapter extends BaseAdapter {

    private List<DubVideoCatalogue> mDubVideoCatalogues = new ArrayList<>();
    private Context mContext;
    private String selectVersionId;

    public DubVideoAlbumAdapter(List<DubVideoCatalogue> dubVideoCatalogues,String selectVersionId, Activity context){
        this.mDubVideoCatalogues = dubVideoCatalogues;
        this.selectVersionId = selectVersionId;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return null == mDubVideoCatalogues ? 0 : mDubVideoCatalogues.size();
    }

    @Override
    public Object getItem(int i) {
        return null == mDubVideoCatalogues ? null : mDubVideoCatalogues.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final ViewHolder viewHolder;
        if (null == view){
            view = LayoutInflater.from(mContext).inflate(R.layout.activity_dub_video_aldum_item,viewGroup,false);
            viewHolder = new ViewHolder();
            viewHolder.dub_aldum_layout = view.findViewById(R.id.dub_aldum_layout);
            viewHolder.dub_aldum_text = view.findViewById(R.id.dub_aldum_text);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }

        setView(viewHolder,i);

        return view;
    }

    private void setView(ViewHolder viewHolder,int index){
        if (mDubVideoCatalogues.get(index).getVersionId().equals(selectVersionId)){
            viewHolder.dub_aldum_text.setTextColor(mContext.getResources().getColor(R.color.green));
            viewHolder.dub_aldum_layout.setBackground(mContext.getResources().getDrawable(R.drawable.dub_activity_aldum_checked));
        }else {
            viewHolder.dub_aldum_text.setTextColor(mContext.getResources().getColor(R.color.black));
            viewHolder.dub_aldum_layout.setBackground(mContext.getResources().getDrawable(R.drawable.dub_activity_aldum_nocheck));
        }
        viewHolder.dub_aldum_text.setText(mDubVideoCatalogues.get(index).getResourceName());

    }

    private static class ViewHolder{
        private RelativeLayout dub_aldum_layout;
        private TextView dub_aldum_text;
    }

    public void setNewData(List<DubVideoCatalogue> dubVideoCatalogues,String versionId){
        this.mDubVideoCatalogues = dubVideoCatalogues;
        this.selectVersionId = versionId;
        notifyDataSetChanged();
    }
   //修改视频选中状态
    public void changeState(String versionId){
        this.selectVersionId = versionId;
        notifyDataSetChanged();
    }
}
